const App = getApp()
Page({
  data: {
    navbar: [{
        name: '进行中',
        type: 'not_use'
      },
      {
        name: '已核销',
        type: 'is_use'
      },
      {
        name: '已过期',
        type: 'is_expire'
      }
    ],
    tabindex: 0,
    type: 'not_use',
    pageShow: false
  },
  onLoad: function (options) {
    let that = this
    that.list()
  },
  onShow: function () {

  },
  bindHeaderTap(e) {
    console.log(e)
    let that = this
    let index = e.target.dataset.index
    that.setData({
      tabindex: index,
      type: that.data.navbar[index].type
    })
    that.list()
  },
  detail(e){
    let that=this
    wx.navigateTo({
      url: '/pages/coupondetail/coupondetail?id='+e.currentTarget.dataset.id,
    })
  },
  list() {
    let that = this
    App.api.$http({
      url: 'user.coupon/lists',
      method: 'Post',
      data: {
        data_type: that.data.type
      }
    }, {}).then(res => {
      that.setData({
        pageShow: true
      })
      res.data.list.forEach(function (item, index) {
        item.min_price = Math.floor(item.min_price)
      })
      that.setData({
        ...res.data
      })
    })
  },
 
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})